package com.itheima.service;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.itheima.pojo.SmsFlashPromotionProductRelation;
import com.itheima.vo.PageResultVo;
import com.itheima.vo.SmsFlashPromotionProduct;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SmsFlashPromotionProductRelationService {
    @DubboReference
    private SmsFlashPromotionProductRelationApi smsFlashPromotionProductRelationApi;

    /**
     * 批量选择商品添加关联
     * @param relationList
     * @return
     */
    public void create(List<SmsFlashPromotionProductRelation> relationList) {
        smsFlashPromotionProductRelationApi.create(relationList);
    }
    /**
     * 删除关联
     * @param id
     * @return
     */
    public void deleteById(Integer id) {
        smsFlashPromotionProductRelationApi.deleteById(id);
    }
    /**
     *
     * @param flashPromotionId
     * @param flashPromotionSessionId 编号
     * @param pageNum
     * @param pageSize
     * @return
     */
    public PageResultVo list(Integer flashPromotionId, Integer flashPromotionSessionId, Integer pageNum, Integer pageSize) {
        IPage<SmsFlashPromotionProduct> iPage=smsFlashPromotionProductRelationApi.list(flashPromotionId,flashPromotionSessionId,pageNum,pageSize);
        List<SmsFlashPromotionProduct> smsFlashPromotionProducts = iPage.getRecords();
        PageResultVo resultVo=new PageResultVo();
        resultVo.setPageNum(pageNum);
        resultVo.setPageSize(pageSize);
        resultVo.setTotal(Convert.toInt(iPage.getTotal()));
        resultVo.setTotalPages(Convert.toInt(iPage.getPages()));
        resultVo.setList(smsFlashPromotionProducts);
        return resultVo;
    }

    /**
     * 修改关联信息
     * @param id
     * @param relation
     * @return
     */
    public void updateById(Integer id, SmsFlashPromotionProductRelation relation) {
        smsFlashPromotionProductRelationApi.updateById(id,relation);
    }

    /**
     * 获取管理商品促销信息
     * @param id
     * @return
     */
    public SmsFlashPromotionProductRelation getRelation(Integer id) {
        return smsFlashPromotionProductRelationApi.getRelation(id);
    }
}
